Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 401/403 apiserver errors do not return 'Status' objects #47384

Merged
merged 1 commit into from
Jul 5, 2017

Conversation

shiywang
Copy link
Contributor

fixes #45970

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 13, 2017
@k8s-github-robot k8s-github-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. release-note-label-needed labels Jun 13, 2017
@shiywang shiywang changed the title Fix 401/403 apiserver errors do not return 'Status' objects [WIP] Fix 401/403 apiserver errors do not return 'Status' objects Jun 13, 2017
@k8s-github-robot k8s-github-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 13, 2017
@shiywang shiywang force-pushed the api403 branch 2 times, most recently from 6a6b608 to 7e12adc Compare June 13, 2017 06:37
@sttts
Copy link
Contributor

sttts commented Jun 13, 2017

@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 14, 2017
@shiywang shiywang changed the title [WIP] Fix 401/403 apiserver errors do not return 'Status' objects Fix 401/403 apiserver errors do not return 'Status' objects Jun 14, 2017
@shiywang
Copy link
Contributor Author

shiywang commented Jun 14, 2017

@sttts testcase added, I also add another filter cases, but seems one unit test failed due to here 0025b07#diff-6445bd63d178373b50fc083b9a043d0bR72
do you think I should change this Authenticate filter at all ?

return
}

gv := schema.GroupVersion{Group: requestInfo.APIGroup, Version: requestInfo.APIVersion}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would move this below the if

glog.V(4).Infof("Forbidden: %#v, Reason: %q", req.RequestURI, reason)
responsewriters.Forbidden(attributes, w, req, reason)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be feasible to modify responsewriters.Forbidden with the Status code? There might be more places where we call it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @sttts I try to modify responsewriters.Forbidden, but I think that would make it almost like responsewriters.ErrorNegotiated, so do you think we can keep it ? I checked, and there's no other places invoke responsewriters.Forbidden

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is this msg := sanitizer.Replace(forbiddenMessage(attributes)) line. We should preserve that. How do the error messages differ now from the old message?

@@ -76,24 +98,6 @@ func WithAuthentication(handler http.Handler, mapper genericapirequest.RequestCo
)
}

func Unauthorized(supportsBasicAuth bool) http.HandlerFunc {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about adding the mapper and serializer to this function? Then we can keep the (now failing) unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, how do you think about now ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@shiywang shiywang force-pushed the api403 branch 3 times, most recently from 1dd2069 to dc0fef5 Compare June 14, 2017 13:50
t.Errorf("unexpected status %q, expected %q", got, expected)
}
if got, expected := decodedData["code"], float64(tc.statusCode); got != expected {
t.Errorf("unexpected code %v, expected %v", got, expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also test reason and message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@shiywang shiywang force-pushed the api403 branch 4 times, most recently from 0abef4a to d319f7a Compare June 15, 2017 13:42
@shiywang
Copy link
Contributor Author

@k8s-bot pull-kubernetes-federation-e2e-gce test this

@@ -64,18 +67,20 @@ func TestForbidden(t *testing.T) {
attributes authorizer.Attributes
reason string
}{
{`User "NAME" cannot GET path "/whatever".`,
{"{\"metadata\":{},\"status\":\"Failure\",\"message\":\" \\\"\\\" is forbidden: User \\\"NAME\\\" cannot GET path \\\"/whatever\\\".\",\"reason\":\"Forbidden\",\"details\":{},\"code\":403}\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With backticks you can make this more readible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

statusCode: http.StatusForbidden,
reqPath: "/apis",
reason: "Forbidden",
message: " \"\" is forbidden: User \"\" cannot get path \"/apis\".: \"Everything is forbidden.\"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backticks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@sttts
Copy link
Contributor

sttts commented Jul 3, 2017

Looks good overall.

/cc @k8s-mirror-api-machinery-api-reviews please take a look that this is what we want.

@smarterclayton @liggitt do you see any issues with existing clients? This changes how errors are returned. Also: do we disclose anything with these more verbose 403 errors that we don't want to?

@shiywang
Copy link
Contributor Author

shiywang commented Jul 3, 2017

/test pull-kubernetes-unit

@smarterclayton
Copy link
Contributor

I think that because we are returning more structured errors, and there was no guarantee that another proxy couldn't be introduced (such as api aggregation), anyone expecting a generic error was already broken. In practice, most people are either gracefully handling our structured error (but would be surprised if we returned a generic error), can handle both, or check status code first and everything else is gravy.

So I don't think this has an issue from API compat that (for instance) changing 200 -> 201 did.

@smarterclayton
Copy link
Contributor

It looks like this handles negotiation properly, which was my primary concern (took a while in 1.5 to get that sorted). So at first glance I don't see anything concerning.

@sttts sttts added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels Jul 4, 2017
@sttts
Copy link
Contributor

sttts commented Jul 4, 2017

@shiywang please squash

@sttts
Copy link
Contributor

sttts commented Jul 4, 2017

/approve

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 4, 2017
@sttts
Copy link
Contributor

sttts commented Jul 4, 2017

/test pull-kubernetes-federation-e2e-gce

@shiywang
Copy link
Contributor Author

shiywang commented Jul 5, 2017

@sttts ok to merge ?

@sttts
Copy link
Contributor

sttts commented Jul 5, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 5, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: shiywang, sttts

Associated issue: 45970

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@shiywang
Copy link
Contributor Author

shiywang commented Jul 5, 2017

/test pull-kubernetes-unit

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 48383, 47384)

@k8s-github-robot k8s-github-robot merged commit c746680 into kubernetes:master Jul 5, 2017
@shiywang shiywang deleted the api403 branch July 5, 2017 09:44
CaoShuFeng added a commit to CaoShuFeng/kubernetes that referenced this pull request Jul 6, 2017
kubernetes#47384 makes 403 errors
return Status Object. How the Content-Type is still "text/plain"
This change fix it.
k8s-github-robot pushed a commit that referenced this pull request Jul 6, 2017
Automatic merge from submit-queue

Fix invalid Content-Type for 403 error

#47384 makes 403 errors return Status Object. However the Content-Type is still "text/plain"
This change fixes it.

Before this change:
kubectl get pods --as=tom
Error from server (Forbidden): {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"pods \"\" is forbidden: User \"tom\" cannot list pods in the namespace \"default\".","reason":"Forbidden","details":{"kind":"pods"},"code":403} (get pods)

After this change:
$ kubectl get pods --as=tom
Error from server (Forbidden): pods "" is forbidden: User "tom" cannot list pods in the namespace "default".



**What this PR does / why we need it**:

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

**Release note**:

```
NONE
```
caesarxuchao pushed a commit to caesarxuchao/apiserver that referenced this pull request Jul 6, 2017
kubernetes/kubernetes#47384 makes 403 errors
return Status Object. How the Content-Type is still "text/plain"
This change fix it.

Kubernetes-commit: 36e0a5ed14ae0fb9fd88980f0fce57d076216e2e
k8s-publish-robot pushed a commit to kubernetes/apiserver that referenced this pull request Jul 7, 2017
kubernetes/kubernetes#47384 makes 403 errors
return Status Object. How the Content-Type is still "text/plain"
This change fix it.

Kubernetes-commit: 36e0a5ed14ae0fb9fd88980f0fce57d076216e2e
RemingtonReackhof pushed a commit to RemingtonReackhof/kubernetes that referenced this pull request Jul 11, 2017
kubernetes#47384 makes 403 errors
return Status Object. How the Content-Type is still "text/plain"
This change fix it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

401/403 apiserver errors do not return 'Status' objects
6 participants